﻿@model Day27Auth.Models.AngularRouteConfigViewModel
@using Day27Auth.Extensions;
<script>
    function Config($routeProvider, $httpProvider) {
        @foreach(var r in Model.Routes)
        {
            var props = r.GetType().GetProperties().ToList();
            var pathProp = props.FirstOrDefault(p => p.Name == "Path");
            props.Remove(pathProp);
            var path = pathProp.GetValue(r);
            var useCtrlAliasProp = props.FirstOrDefault(p => p.Name == "UseCtrlAlias");
            var useCtrlAlias = bool.Parse(useCtrlAliasProp.GetValue(r).ToString());
            props.Remove(useCtrlAliasProp);
            @:$routeProvider.when('@path', {
            foreach(var prop in props)
            {
                @prop.Name.ToCamelCase()@: : '@prop.GetValue(r)',
            }
            
            if (useCtrlAlias)
            {
                @:controllerAs: 'vm'
            }
            
            @:});
        }
        $routeProvider.otherwise({
            redirectTo: '/'
        });

        $httpProvider.interceptors.push('AuthFactory');
    }

    Config.$inject = ['$routeProvider', '$httpProvider'];
</script>
    
